/**
 * First we will load all of this project's JavaScript dependencies which
 * includes Vue and other libraries. It is a great starting point when
 * building robust, powerful web applications using Vue and Laravel.
 */

require('./bootstrap');

import Vue from 'vue'
import router from './router'
import store from './store'
import { sync } from 'vuex-router-sync'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import 'quill/dist/quill.snow.css'
import App from './App.vue'
import '../fonts/iconfont.css'

Vue.use(ElementUI, {
	size: 'small',
});

sync(store, router);

Vue.component('collapse-view',
	require('./components/Collapse.vue')
);

/**
 * 路由拦截
 */
router.beforeEach((to, from, next) => {
	/**
	 * 判断前往的路由是否需要身份验证
	 */
	if (to.matched.some(record => record.meta.requiresAuth)) {
		const access_token = store.state.account.access_token;
		//通过access_token判断用户是否已经登录
		if (!access_token) {
			next({
				path: '/login'
			})
		} else {
			next()
		}
	} else {
		next()
	}
});

router.afterEach(() => {
});

/**
 * Next, we will create a fresh Vue application instance and attach it to
 * the page. Then, you may begin adding components to this application
 * or customize the JavaScript scaffolding to fit your unique needs.
 */

new Vue({
	router,
	store,
	render: (h) => h(App)
}).$mount('#app');
